package com.nulldev.util.networking.rudp;

public class NetworkPackage {
	// Sequence number to keep tracking what package have been sent
	private volatile int sequenceNumber;

	// The data that was sent with this sequence Number so we can resend it if
	// needed
	private volatile byte[] dataSent;

	// When did we send the data
	private volatile long sentTime;

	// How many times the package have tried to be resent
	private volatile int resent = 0;

	private volatile int splitSequenceNumber;

	private volatile boolean resentPackage = false;

	private volatile NetworkSendType networkSendType;

	public NetworkPackage() {
	}

	public void setValues(int sequenceNumber, NetworkSendType networkSendType) {
		this.sequenceNumber = sequenceNumber;
		this.networkSendType = networkSendType;
		sentTime = System.currentTimeMillis();
		resetValues();
	}

	public void setValues(int sequenceNumber, byte[] dataSent, NetworkSendType networkSendType) {
		this.sequenceNumber = sequenceNumber;
		this.dataSent = dataSent;
		sentTime = System.currentTimeMillis();
		this.networkSendType = networkSendType;
		resetValues();
	}

	public void setValues(int sequenceNumber, byte[] dataSent, NetworkSendType networkSendType, int splitSequenceNumber) {
		this.sequenceNumber = sequenceNumber;
		this.dataSent = dataSent;
		sentTime = System.currentTimeMillis();
		this.networkSendType = networkSendType;
		this.splitSequenceNumber = splitSequenceNumber;
		resetValues();
	}

	public void resetValues() {
		resent = 0;
		resentPackage = false;
	}

	/*
	 * public NetworkPackage(int sequenceNumber, NetworkSendType networkSendType) {
	 * this.sequenceNumber = sequenceNumber; this.networkSendType = networkSendType;
	 * sentTime = System.currentTimeMillis(); } public NetworkPackage(int
	 * sequenceNumber, byte[] dataSent, NetworkSendType networkSendType) {
	 * this.sequenceNumber = sequenceNumber; this.dataSent = dataSent; sentTime =
	 * System.currentTimeMillis(); this.networkSendType = networkSendType; } public
	 * NetworkPackage(int sequenceNumber, byte[] dataSent, NetworkSendType
	 * networkSendType, int splitSequenceNumber) { this.sequenceNumber =
	 * sequenceNumber; this.dataSent = dataSent; sentTime =
	 * System.currentTimeMillis(); this.networkSendType = networkSendType;
	 * this.splitSequenceNumber = splitSequenceNumber; }
	 */

	public void resendData(int sequenceNumber) {
		this.sequenceNumber = sequenceNumber;
		this.sentTime = System.currentTimeMillis();
		resentPackage = true;
		resent++;
	}

	public int getSequenceNumber() {
		return sequenceNumber;
	}

	public void setSequenceNumber(int sequenceNumber) {
		this.sequenceNumber = sequenceNumber;
	}

	public byte[] getDataSent() {
		return dataSent;
	}

	public long getSentTime() {
		return sentTime;
	}

	public int getResent() {
		return resent;
	}

	public NetworkSendType getNetworkSendType() {
		return networkSendType;
	}

	public int getSplitSequenceNumber() {
		return splitSequenceNumber;
	}

	public boolean isResentPackage() {
		return resentPackage;
	}
}
